﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Passwords.Models;

namespace Passwords.Utils
{
    public class PasswordComparer : IComparer<PasswordContract>
    {
        private string name;
        private PasswordContract password;

        public PasswordContract Password
        {
            get { return password; }
            set
            {
                password = value;
                string n = password.Name;
                name = n != null ? n.ToLowerInvariant() : null;
                CompareName = name;
            }
        }

        public string CompareName { get; set; }


        public int Compare(PasswordContract x, PasswordContract y)
        {
            if (x == password)
            {
                return string.CompareOrdinal(CompareName.ToLowerInvariant(), name);
            }
            return string.CompareOrdinal(x.Name.ToLowerInvariant(), name);
        }
    }
}
